package cn.wolfcode.student.dao.impl;

import cn.wolfcode.domain.QueryObject;
import cn.wolfcode.student.dao.StudentDAO;
import cn.wolfcode.student.domain.Student;
import cn.wolfcode.student.util.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class StudentDAOImpl implements StudentDAO {
    private SqlSession ss = MybatisUtils.getSql();
    @Override
    public void add(Student student) {
        ss.insert("cn.wolfcode.student.mapper.StudentMapper.add", student);
        ss.commit();
    }

    @Override
    public void delById(Long id) {
        ss.delete("cn.wolfcode.student.mapper.StudentMapper.delById", id);
        ss.commit();

    }

    @Override
    public void edit(Student student) {
        ss.update("cn.wolfcode.student.mapper.StudentMapper.edit", student);
        ss.commit();
    }

    @Override
    public Student selOne(Long id) {
        return ss.selectOne("cn.wolfcode.student.mapper.StudentMapper.selOne", id);
    }

    @Override
    public List<Student> selAll() {
        return ss.selectList("cn.wolfcode.student.mapper.StudentMapper.selAll");
    }

    @Override
    public List<Student> selForList(QueryObject qo) {
        return ss.selectList("cn.wolfcode.student.mapper.StudentMapper.selForList", qo);
    }

    @Override
    public int selForCount(QueryObject qo) {
        return ss.selectOne("cn.wolfcode.student.mapper.StudentMapper.selForCount", qo);
    }
}
